/*
 * @Author: 0x9DEFA478
 * @Date: 2022-01-23 15:48:40
 * @LastEditTime: 2022-02-25 17:13:57
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#ifndef __Cartridge_H_NES_Cartridge_H_
#define __Cartridge_H_NES_Cartridge_H_
#include "../H_NES.h"




typedef union{
  struct{
    Hbyte Reg_8000;
    Hbyte Reg_A000;
    Hbyte Reg_C000;
    Hbyte Reg_E000;

    Hbyte LastWrite;

    struct{
      Hbyte Value;
      Hbyte NumOfBit;
    }LoadRegister;

    struct{
      Hbyte* Base8000_16KB[2];
      Hbyte* Base6000_8KB;
    }PRG_Banks;
    struct{
      Hbyte* Base0000_4KB[2];
    }CHR_Banks;
  }Mapper1;
  struct{
    struct{
      Hbyte* Base8000_16KB[2];
    }PRG_Banks;
  }Mapper2;
  struct{
    struct{
      Hbyte* Base0000_8KB;
    }CHR_Banks;
  }Mapper3;
  struct{
    Hbyte Reg_8000;
    Hbyte Reg_A001;
    Hbyte Reg_C000;

    Hbyte IRQ_Timer_Cnt;
    Hbyte IRQ_Timer_IsReload;
    Hbyte IRQ_Enable;

    Hbyte R[8];
    

    struct{
      Hbyte* Base8000_8KB[4];
    }PRG_Banks;
    struct{
      Hbyte* Base0000_1KB[8];
    }CHR_Banks;
  }Mapper4;
}H_NES_Cartridge_Mapper;




typedef struct{

  struct{
    Hbyte* PRG_ROM;
    Huint32 PRG_ROM_Size;
    Hbyte* CHR_ROM;
    Huint32 CHR_ROM_Size;
    Hbyte* PRG_RAM;
    Hint32 PRG_RAM_Size;
    Hbyte* CHR_RAM;
    Hint32 CHR_RAM_Size;

    void (*DeInit)(void*);

    H_NES_Cartridge_Mapper SpecificMapper;
  }Mapper;
  

  Hbyte (*PRG_Read)(Huint16,void*);
  void (*PRG_Write)(Hbyte,Huint16,void*);
  Huint16 (*PRG_Read16)(Huint16,void*);

  Hbyte (*CHR_Read)(Huint16,void*);
  void (*CHR_Write)(Hbyte,Huint16,void*);

  struct{
    int Size;
    void (*Get)(void*,void*);
    void (*Load)(void*,void*);
  }Progress;

  struct{
    void (*MMC3_A12_Rise)(unsigned int,void*);
  }Option;

}H_NES_Cartridge;




#endif //__Cartridge_H_NES_Cartridge_H_
